home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / 8087.arc / 87MATMUL.BAS (.txt) < prev    next >
Encoding:
GW-BASIC  |  1985-02-13  |  7.6 KB  |  178 lines

  1. 1000  '        |----------------------------------------|
  2. 1010  '        |        Matrix Premultiplication        |
  3. 1020  '        |        of a Three-Element Vector       |
  4. 1030  '        |        Personnel Computer Age 2.12     |
  5. 1040  '        |----------------------------------------|
  6. 1050  '
  7. 1060                              'Reserve space for
  8. 1070                              'machine language subroutine
  9. 1080  CLEAR ,29999
  10. 1090                              'Initialize screen,
  11. 1100                              'variable types,
  12. 1110                              'and data display formats
  13. 1120        :PRINT"Storing machine code...."
  14. 1130    DEFINT A-Z
  15. 1140    DIM A!(2,2), ACOPY!(2,2), X!(2), B!(2)
  16. 1150    F1$ = "  ##.####^^^^    ##.####^^^^    ##.####^^^^"
  17. 1155    F1$ = F1$ + "                   ##.####^^^^"
  18. 1160    F2$ = "##.####^^^^"
  19. 1170                              'Store machine language
  20. 1180                              'subroutine and check for
  21. 1185                              'errors in data statements
  22. 1190                              '(i.e., machine language
  23. 1200                              'hexidecimal values, "M")
  24. 1210    ADDR = 30000: CHKSUM = 19443
  25. 1220    READ M: IF M<>1000 THEN POKE ADDR,M:CHKSUM=CHKSUM-M:ADDR=ADDR+1:GOTO 1220ELSE IF CHKSUM=0 THEN 1320
  26. 1230                              '
  27. 1240                              'Checksum error
  28. 1250                              '
  29. 1260    PRINT:PRINT "Coding errors in MATMUL87...":PRINT "please check DATA statements."
  30. 1270    '
  31. 1280    END
  32. 1290                              '
  33. 1300                              'Input transformation
  34. 1310                              'matrix, "A"
  35. 1320    CLS:PRINT "Please provide the elements";:PRINT " of the transformation matrix."
  36. 1330    PRINT
  37. 1340    FOR R=0 TO 2:FOR C=0 TO 2
  38. 1350      LOCATE 10,10:PRINT "Row ";R+1; ", Column"; C+1;:INPUT  A!(R,C)
  39. 1360      ACOPY!(R,C)=A!(R,C)
  40. 1370      LOCATE 10,10:PRINT SPC(30)
  41. 1380    NEXT:NEXT
  42. 1390                              '
  43. 1400                              'Input vector to be
  44. 1410                              'transformed, "X"
  45. 1420    CLS:PRINT "Please provide the elements";:PRINT " of the input vector."
  46. 1430    PRINT
  47. 1440    FOR R=0 TO 2
  48. 1450      LOCATE 10,10:PRINT "Row "; R+1;:INPUT X!(R)
  49. 1460      LOCATE 10,10:PRINT SPC(30)
  50. 1470    NEXT
  51. 1480                              'Print transformation
  52. 1490                              'matrix and input
  53. 1500                              'vector elements
  54. 1510    CLS:PRINT
  55. 1520    PRINT "      The Transformation Matrix is:";:PRINT SPC(22); "The Input vector is:"
  56. 1530    PRINT "      ";STRING$(29,45);:PRINT SPC(22);STRING$(20,45)
  57. 1540    FOR R=0 TO 2
  58. 1550      PRINT
  59. 1560      PRINT USING F1$;A!(R,0),A!(R,1),A!(R,2),X!(R)
  60. 1570    NEXT
  61. 1580                              'Call the 8087 subroutine,
  62. 1590                              'or substitute the "regular"
  63. 1600                              'BASIC subroutine provided
  64. 1610                              'in the text.
  65. 1620    MATMULT87 = 30000
  66. 1630    CALL MATMULT87( ACOPY!(0,0),X!(0) )
  67. 1640    FOR J=0 TO 2:B!(J)=X!(J):NEXT
  68. 1650                              'Print the transformed
  69. 1660                              'vector, "B" ( where B=AX )
  70. 1670                              '
  71. 1680    LOCATE 12,27: PRINT "The Transformed Vector is:"
  72. 1690    LOCATE 13,27: PRINT STRING$(26,45)
  73. 1700    FOR R = 0 TO 2
  74. 1710      PRINT
  75. 1720      PRINT TAB(34);:PRINT USING F2$;B!(R)
  76. 1730    NEXT
  77. 1740                              '
  78. 1750                              'Calculate another or exit
  79. 1760                              '
  80. 1770    LOCATE 22,2:PRINT "Do you wish to calculate another (y/n) ?"
  81. 1780    Q$=INKEY$:IF Q$="" THEN 1780 ELSE IF Q$="y" OR Q$="Y" THEN 1320 ELSE IF  Q$="n" OR Q$="N" THEN 1790 ELSE BEEP: GOTO 1780
  82. 1790    CLS
  83. 1800    END
  84. 1810    '
  85. 1820    ' |----------------------------------|
  86. 1830    ' |   MATMULT87:  8087 3x3 Matrix    |
  87. 1840    ' |    Vector-Premultiplication      |
  88. 1850    ' |            Subroutine            |
  89. 1860    ' |----------------------------------|
  90. 1870                    'Set argument addresses
  91. 1880   DATA &h55:                     'push  bp
  92. 1890   DATA &h8B, &hEC:               'mov   bp,sp
  93. 1900   DATA &h8B, &h76, &h08:         'mov   si,[bp]+8
  94. 1910   DATA &h8B, &h7E, &h06:         'mov   di,[bp]+6
  95. 1920                   '
  96. 1930                   'Convert the "abandoned"
  97. 1940                   'transformation matrix, ACOPY!
  98. 1950   DATA &hB9, &h09, &h00:         'mov   cx,9
  99. 1960   DATA &h8B, &h44, &h02:         'mov   ax,[si]+2
  100. 1970   DATA &h80, &hFC, &h02:         'cmp   ah,2
  101. 1980   DATA &h72, &h0A:               'jb    (+10)
  102. 1990   DATA &h80, &hEC, &h02:         'sub   ah,2
  103. 2000   DATA &hD0, &hC0:               'rol   al,1
  104. 2010   DATA &hD1, &hC8:               'ror   ax,1
  105. 2020   DATA &h89, &h44, &h02:         'aov   [si]+2,ax
  106. 2030   DATA &h83, &hC6, &h04:         'add   si,4
  107. 2040   DATA &hE2, &hE9:               'loop  (-23)
  108. 2050   DATA &h8B, &h76, &h08:         'mov   si,[bp]+8
  109. 2060                   '
  110. 2070                   'Repeat the process for
  111. 2080                   'the input vector X!
  112. 2090   DATA &hB9, &h03, &h00:         'mov   cx,3
  113. 2100   DATA &h8B, &h45, &h02:         'mov   ax,[di]+2
  114. 2110   DATA &h80, &hFC, &h02:         'cmp   ah,2
  115. 2120   DATA &h72, &h0A:               'jb    (+10)
  116. 2130   DATA &h80, &hEC, &h02:         'sub   ah,2
  117. 2140   DATA &hD0, &hC0:               'rol   al,1
  118. 2150   DATA &hD1, &hC8:               'ror   ax,1
  119. 2160   DATA &h89, &h45, &h02:         'mov   [di]+2,ax
  120. 2170   DATA &h83, &hC7, &h04:         'add   di,4
  121. 2180   DATA &hE2, &hE9:               'loop  (-23)
  122. 2190   DATA &h8B, &h7E, &h06:         'mov   di,[bp]+6
  123. 2200                   'Perform the
  124. 2210                   'matrix premultiplication.
  125. 2220                   'Begin by setting a loop counter
  126. 2230                   'and initializing the 8087.
  127. 2240   DATA &hB9, &h03, &h00:         'mov   cx,3
  128. 2250   DATA &h9B, &hDB, &hE3:         'finit
  129. 2260                   '
  130. 2270                   'Now place the components of X!
  131. 2280                   'on the 8087 register stack
  132. 2290   DATA &h9B, &hD9, &h05:         'fld   dword ptr [di]
  133. 2300   DATA &h9B, &hD9, &h45, &h04:   'fld   dword ptr [di]+4
  134. 2310   DATA &h9B, &hD9, &h45, &h08:   'fld   dword ptr [di]+8
  135. 2320                         '
  136. 2330                         'Execute the premultiplication
  137. 2340                         'loop
  138. 2350   DATA &h9B, &hD9, &h04:         'fld   dword ptr [si]
  139. 2360   DATA &h9B, &hD8, &hCB:         'fmul  st,st(3)
  140. 2370   DATA &h9B, &hD9, &h44, &h0C:   'fld   dword ptr [si]+12
  141. 2380   DATA &h9B, &hD8, &hCB:         'fmul  st,st(3)
  142. 2390   DATA &h9B, &hDE, &hC1:         'faddp st(1),st
  143. 2400   DATA &h9B, &hD9, &h44, &h18:   'fld   dword ptr [si]+24
  144. 2410   DATA &h9B, &hD8, &hCA:         'fmul  st,st(2)
  145. 2420   DATA &h9B, &hDE, &hC1:         'faddp st(1),st
  146. 2430   DATA &h9B, &hD9, &h1D:         'fstp  dword ptr [di]
  147. 2440   DATA &h9B:                     'fwait
  148. 2450   DATA &h83, &hC6, &h04:         'add   si,4
  149. 2460   DATA &h83, &hC7, &h04:         'add   di,4
  150. 2470   DATA &hE2, &hDA:               'loop  (-38)
  151. 2480                   '
  152. 2490                   'Reset SI and DI to point to
  153. 2500                   'ACOPY!(0,0) and X!(0)
  154. 2510   DATA &h8B, &h76, &h08:         'mov   si,[bp]+8
  155. 2520   DATA &h8B, &h7E, &h06:         'mov   di,[bp]+6
  156. 2530                   '
  157. 2540                   'Reconvert the results for
  158. 2550                   'use by BASIC
  159. 2560   DATA &hB9, &h03, &h00:         'mov   cx,3
  160. 2570   DATA &h8B, &h45, &h02:         'mov   ax,[di]+2
  161. 2580   DATA &hD1, &hC0:               'rol   ax,1
  162. 2590   DATA &hD0, &hC8:               'ror   al,1
  163. 2600   DATA &h80, &hFC, &h00:         'cmp   ah,0
  164. 2610   DATA &h74, &h03:               'je    (+3)
  165. 2620   DATA &h80, &hC4, &h02:         'add   ah,2
  166. 2630   DATA &h89, &h45, &h02:         'mov   [di]+2,ax
  167. 2640   DATA &h83, &hC7, &h04:         'add   di,4
  168. 2650   DATA &hE2, &hE9:               'loop  (-23)
  169. 2660                   '
  170. 2670                   'Restore the BP register
  171. 2680                   'and return to BASIC
  172. 2690   DATA &h5D:                     'pop   bp
  173. 2700   DATA &hCA, &h04, &h00:         'ret   4
  174. 2710                   '
  175. 2720                   '"Flag" value signals end of
  176. 2730                   'data to terminate loops
  177. 2740   DATA 1000
  178.